package testing.module;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;

import utilities.manager.definederunner.GameRunner;
import utilities.module.definedmods.GameScreen;

public class GameScreenTest extends GameScreen
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4970555613853341873L;
	
	private Rectangle rect = null;
	private int startX = 0;
	private int startY = 0;

	public GameScreenTest(GameRunner runner)
	{
		super(runner);
		
		System.out.println();
		System.out.println("MouseEvent.MOUSE_CLICKED = " + MouseEvent.MOUSE_CLICKED);
		System.out.println("MouseEvent.MOUSE_PRESSED = " + MouseEvent.MOUSE_PRESSED);
		System.out.println("MouseEvent.MOUSE_RELEASED = " + MouseEvent.MOUSE_RELEASED);
		System.out.println("MouseEvent.MOUSE_MOVED = " + MouseEvent.MOUSE_MOVED);
		System.out.println("MouseEvent.MOUSE_ENTERED = " + MouseEvent.MOUSE_ENTERED);
		System.out.println("MouseEvent.MOUSE_EXITED = " + MouseEvent.MOUSE_EXITED);
		System.out.println("MouseEvent.MOUSE_DRAGGED = " + MouseEvent.MOUSE_DRAGGED);
		System.out.println();
	}
	
	public void drawMe(Graphics g)
	{		
		Color c = g.getColor();
		
		super.drawMe(g);
		
		if(rect != null)
		{
			
			g.setColor(Color.red);
			
			g.drawRect(rect.x, rect.y, rect.width, rect.height);
		}
		
		g.setColor(Color.blue);

		g.drawLine(this.getWidth() / 2, 0, this.getWidth() / 2, this.getHeight());
		g.drawLine(0, this.getHeight() / 2, this.getWidth(), this.getHeight() / 2);
		
		g.setColor(c);
	}
	
	public void mouseMoved(MouseEvent e)
	{
		System.out.println("Mouse Moved @ " + System.currentTimeMillis());
	}

	public void mouseClicked(MouseEvent e)
	{
		//System.out.println("Mouse click occurred @ (" + getRunner().getMouseX() + ", " + this.getRunner().getMouseY() + ")");
		//if(rect == null) rect = new Rectangle(getRunner().getMouseX(), this.getRunner().getMouseY(), 0, 0);
		
//		System.out.println("Clicked e's event type = " + e.getID());
//		System.out.println("MouseEvent.MOUSE_CLICKED = " + MouseEvent.MOUSE_CLICKED);
//		System.out.println();
		
		//System.out.println("Mouse Down");
	}
	
	public void mouseDragged(MouseEvent e)
	{
		//System.out.println("Mouse drag occurred @ (" + getRunner().getMouseX() + ", " + this.getRunner().getMouseY() + ")");
		
		if(rect == null)
		{
			startX = getRunner().getMouseX();
			startY = getRunner().getMouseY();
			rect = new Rectangle(getRunner().getMouseX(), this.getRunner().getMouseY(), 0, 0);
		}
		else
		{
			/*
			if(getRunner().getMouseX() < startX)
			{
				rect.x = getRunner().getMouseX();
				//rect.width = startX - getRunner().getMouseX();
			}
			else
			{
				rect.x = startX;
				//rect.width = getRunner().getMouseX() - rect.x;
			}
			*/
			
			rect.x = Math.min(getRunner().getMouseX(), startX);			
			rect.width = Math.abs(startX - getRunner().getMouseX());
				
			/*
			if(getRunner().getMouseY() < startY)
			{
				rect.y = getRunner().getMouseY();
				//rect.height = startY - this.getRunner().getMouseY();
			}
			else
			{
				rect.y = startY;
				//rect.height = getRunner().getMouseY() - rect.y;
			}
			*/
			
			rect.y = Math.min(getRunner().getMouseY(), startY);
			rect.height = Math.abs(startY - getRunner().getMouseY());
		}

//		System.out.println("Clicked e's event type = " + e.getID());
//		System.out.println("MouseEvent.MOUSE_DRAGGED = " + MouseEvent.MOUSE_DRAGGED);
//		System.out.println();
		
		System.out.println("Mouse Dragged @ " + System.currentTimeMillis());
	}
	
	public void mouseReleased(MouseEvent e)
	{
		//System.out.println("Mouse release occurred @ (" + getRunner().getMouseX() + ", " + this.getRunner().getMouseY() + ")");
		if(rect != null) rect = null;

//		System.out.println("Clicked e's event type = " + e.getID());
//		System.out.println("MouseEvent.MOUSE_RELEASED = " + MouseEvent.MOUSE_RELEASED);
//		System.out.println();
		
		//System.out.println("Mouse Up");
	}
}
